package com.duke.shaking;



import android.app.Application;
import android.content.Intent;

import com.duke.shaking.pojo.User;
import com.duke.shaking.services.FetcherService;
import com.duke.shaking.services.MsgSenderService;
import com.duke.shaking.services.PopupUpdateAlertService;
import com.duke.shaking.storage.DataManager;
import com.duke.shaking.storage.OwnerManager;
import com.duke.shaking.utils.AppUtils;
import com.duke.shaking.utils.DeviceUtils;
import com.duke.shaking.utils.LocationUtils;
import com.duke.shaking.utils.PhotoUtils;

public class ShakeApplication extends Application {

	private static ShakeApplication sharedApp;
	
	public boolean checkUpdate = false;
	public int lastVersionCode = 0;
	public String lastVersionName = null;
	public String updateUrl = null;
	
	public boolean userCompleteChecked = false;
	
	public static ShakeApplication getShared() {
		return sharedApp;
	}
	
	@Override
	public void onCreate() {
		sharedApp = this;
		super.onCreate();
		
		DeviceUtils.init(this);
        AppUtils.init(this);
        LocationUtils.getCityNameByLocation(this);
        
        OwnerManager.createShared(this);

        PhotoUtils.init(this);
	}
	
	public void prepareDataManager(String userMobile) {
		DataManager.prepareDataManager(this, userMobile);
	}
	
	public void afterLogin(User user) {
		/* do something after the user login */
		ShakeApplication.getShared().prepareDataManager(user.getTelNo());
		startService(new Intent(this, FetcherService.class));
		startService(new Intent(this, MsgSenderService.class));
		//Intent intent = new Intent(this, PopupUpdateAlertService.class);
		//intent.putExtra("user", user);
		//this.startService(intent);
	}
	
	public void afterLogout() {
		/* do something after the user logout */
		stopService(new Intent(this, FetcherService.class));
		stopService(new Intent(this, MsgSenderService.class));
	}
}
